<template>
  <audit-trade :id="id" tradeType=1 @audit-trade="auditSell"></audit-trade>
</template>
<script type="text/ecmascript-6">
  import AuditTrade from '@/views/wms/trade/buy-back/auditTrade';
  import mValidate from 'utils/common-method/validate/index';
  export default {
    props: {
      id: [String, Number]
    },
    components: {AuditTrade},
    data() {
      return {
        auditForm: {
          id: '', // 主键id
          auditType: '', // 审核类型(1:通过 2:不通过)
          arType: 1, // 交易类型(1:出售 2:回购)
          applyDesc: '', // 审核说明 varchar(200)
          repurchaseLastDate: '', // 最晚回购日期 - 出售填写
          sellDate: '', // 出售日期 - 出售填写
          version: '', // 版本号
          wmsArAuditGoodsDtoList: '' // 审核出售/回购-货物信息
        }

      };
    },
    methods: {
      // 审核出售
      auditSell(data) {
        let verify = data.auditType === 1;
        // 判断是否没有选择出售日期
        data.sellDate = data.tradeDate;
        if (verify && mValidate.stringIsNullOrEmpty(data.sellDate)) {
          this.errorTip('出售日期不可为空');
          return;
        }
        // 判断是否没有选择最晚回购日期
        if (verify && mValidate.stringIsNullOrEmpty(data.repurchaseLastDate)) {
          this.errorTip('最晚回购日期不可为空');
          return;
        }
        let arrayIsNullOrEmpty = mValidate.arrayIsNullOrEmpty(data.wmsArAuditGoodsDtoList); // 判断列表是否null
        let goodsLen = !arrayIsNullOrEmpty ? data.wmsArAuditGoodsDtoList.length : 0;
        let pass = !arrayIsNullOrEmpty;
        // 校验每种货物的交易金额
        for (let i = 0; i < goodsLen; i++) {
          if (!data.wmsArAuditGoodsDtoList[i].transactionAmount || data.wmsArAuditGoodsDtoList[i].transactionAmount <= 0) {
            pass = false;
            break;
          }
        }
        if (verify && !pass) {
          this.errorTip('每种货物的交易金额不可为空');
          return;
        }
        let message = data.auditType === 1 ? '确定审核通过吗？' : '确定审核不通过吗？';
        this.confirmModel(message, '/maliwms/ar/auditAr', data, (response) => {
          if (response.code === 200) {
            this.successTip('提交成功', 3000);
            this.$emit('closeRefresh');
          }
        });
      }
    }
  };
</script>


<!--
<template>
  <div class="page-audit-sell">
    <base-info class="base-info" categoryTitle="基本信息" :params="params" :data="data">
    </base-info>
    <div class="goods-title">货物明细</div>
    <egrid class="egrid-class" border
           :header-cell-style="getHeaderCellClass"
           :data="data.goodsDetails"
           :columns="goodsColumns"
           :columns-schema="columnsSchema"
           :columns-props="columnsProps">
    </egrid>

    <div class="goods-title">交易信息</div>
    <el-form :inline="true" :model="auditForm" ref="auditForm">
      <div class="trade-date">
        <el-form-item label="出售日期" prop="sellDate">
          <el-date-picker class="block"
                          v-model="auditForm.sellDate"
                          type="date"
                          placeholder="选择出售日期"
                          value-format="yyyy-MM-dd">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="最晚回购日期" prop="repurchaseLastDate">
          <el-date-picker class="block"
                          v-model="auditForm.repurchaseLastDate"
                          type="date"
                          placeholder="选择最晚回购日期"
                          value-format="yyyy-MM-dd">
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <div class="text-class">货物期望回购期限：<span>{{data.repurchaseDays}}</span></div>
        </el-form-item>
      </div>
    </el-form>
    <egrid border
           :header-cell-style="getHeaderCellClass"
           :data="data.goodsDetails"
           :columns="tradeColumns"
           :columns-schema="columnsSchema"
           :columns-props="columnsProps">
    </egrid>
    <div style="margin-top: 20px">
      <input-com :headTitle="'审核说明(选填)'" :inputValue="auditForm.applyDesc" @getInputVal="getInputVal"
                 :headSonTitle="'填写审核说明'"></input-com>
      <el-row class="btnFrameClass">
        <el-button class="singleBtnClass" type="primary" @click="saveData('addForm')">审核通过</el-button>
        <el-button class="singleBtnClass" type="primary" plain @click="submitForm('addForm')">审核不通过</el-button>
      </el-row>
    </div>
  </div>
</template>
<script type="text/ecmascript-6">
  import BaseInfo from 'components/wms/comm/BaseInfo';
  import inputCom from 'components/input/baseTitleInput';
  import mValidate from 'utils/common-method/validate/index';
  let that;
  // 操作按钮
  var Btn = {
    template: `<div style="display:flex; width: 100%;flex-wrap: wrap">
        <el-button type="primary" plain @click="viewdetail(row)">查看</el-button>
      </div>`,
    props: ['row'],
    computed: {},
    methods: {
      viewdetail(val) {
        console.log('view detail&#45;&#45;&#45;&#45;&#45;&#45;row: ' + JSON.stringify(val));
        this.$emit('show-detail', val);
      }
    }
  };
  export default{
    props: {
      id: [String, Number]
    },
    components: {BaseInfo, inputCom},
    data() {
      return {
        params: [
          {
            label: '出售方',
            labelIcon: ['icon maliiconfont maliicon-storehouse'],
            delimiter: ' ',
            key: 'sellerName'
/*            baseClass: ['base-single'], // 子组件的基本样式
            labelClass: ['label-class'], // 标签的样式
            valueClass: ['value-class'] // 内容样式 */
          },
          {
            label: '交易对象',
            labelIcon: ['icon maliiconfont maliicon-img_details_figure'],
            delimiter: ' ',
            key: 'buyerName'
          },
          {
            label: '保管人',
            labelIcon: ['icon maliiconfont maliicon-img_details_relation'],
            key: 'storageCompanyName',
            delimiter: ' '
          },
          {
            label: '保管仓',
            labelIcon: ['icon maliiconfont maliicon-img_details_calendar'],
            delimiter: ' ',
            key: 'storageName'
          },
          {
            label: '申请人',
            labelIcon: ['icon maliiconfont maliicon-img_details_type'],
            delimiter: ' ',
            key: 'creator'
          },
          {
            label: '申请时间',
            labelIcon: ['icon maliiconfont maliicon-img_detailse_source'],
            delimiter: ' ',
            key: 'createdTime'
          }
        ],
        auditForm: {
          id: '', // 主键id
          auditType: '', // 审核类型(1:通过 2:不通过)
          arType: 1, // 交易类型(1:出售 2:回购)
          applyDesc: '', // 审核说明 varchar(200)
          repurchaseLastDate: '', // 最晚回购日期 - 出售填写
          sellDate: '', // 出售日期 - 出售填写
          version: '', // 版本号
          wmsArAuditGoodsDtoList: '' // 审核出售/回购-货物信息
        },
        data: {
          sellerName: '秦沃农业发展公司',
          buyerName: '平安商贸',
          storageCompanyName: '深圳市金宇物流有限公司',
          storageName: '马力1号标准仓',
          creator: '刘芳',
          createdTime: '2019-09-10 13:06',
          repurchaseDays: 60,
          goodsDetails: [
            {
              arId: null, // 约定回购id
              busNo: '20180802', // 仓单业务流水码
              cntrNo: 'HJGH0989878', // 柜号
              countryOrigin: '澳大利亚', // 原产地
              goodsId: null, // 货物id
              goodsName: '牛眼肉去盖', // 货物名称
              id: null, // 主键id
              packageDesc: '纸箱', // 包装描述
              packageId: null, // 包装Id
              productDate: '201801', // 生产日期
              refAvgWeight: 25, // 参考平均重量
              scanWeight: '', // 扫码重量
              sellNum: 80, // 出售数量
              transactionAmount: null, // 交易金额
              unit: null, // 单位
              unitDesc: '件', // 单位描述
              vendor: '218', // 生产厂家
              wrId: null // 仓单编号
            }
          ]
        },
        contentClass: ['content-class'],
        columnsSchema: {
//          '订单号' : { minWidth: 100},
//          '操作': { fixed: 'right' }
        },
        // columnsProps 用于定义所有 columns 公共的属性，
        // 这里属性可以参考这里： http://element.eleme.io/#/zh-CN/component/table#table-column-attributes
        columnsProps: {
          height: 40,
          align: 'center',
          showOverflowTooltip: true
        },
        // 货物信息、交易信息公共列
        baseColumns: [
          {
            label: '仓单业务号',
            prop: 'busNo'
          },
          {
            label: '货物名称',
            prop: 'goodsName'
          },
          {
            label: '柜号',
            prop: 'cntrNo'
          },
          {
            label: '生产厂家',
            prop: 'vendor'
          },
          {
            label: '原产地',
            prop: 'countryOrigin'
          }
        ],
        goodsAdditionalCols: [
          /*         {
           label: '仓单业务号',
           prop: 'busNo'
           },
           {
           label: '货物名称',
           prop: 'goodsName'
           },
           {
           label: '柜号',
           prop: 'cntrNo'
           },
           {
           label: '生产厂家',
           prop: 'vendor'
           },
           {
           label: '原产地',
           prop: 'countryOrigin'
           }, */
          {
            label: '包装',
            prop: 'packageDesc'
          },
          {
            label: '生产日期',
            prop: 'productDate'
          },
          {
            label: '出售数量',
            prop: 'sellNum'
          },
          {
            label: '单位',
            prop: 'unitDesc'
          },
          {
            label: '参考出售重量(kg)',
            prop: 'refAvgWeight'
          },
          {
            label: '对应仓单',
            width: 116,
            component: Btn, // 'el-button'
            listeners: {
              'show-detail' (data) {
                console.log('custom-event: ', JSON.stringify(data));
                that.showDetail(data);
              }
            },
            propsHandler: function ({ row, col, column }) {
              return {row, col, column};
            }
          }
        ],
        tradeAdditionalColumns: [
          {
            label: '生产日期',
            prop: 'productDate'
          },
          {
            label: '出售数量',
            prop: 'sellNum'
          },
          {
            label: '参考出售重量(kg)',
            prop: 'refAvgWeight'
          },
          {
            label: '抄码重量（kg）',
            prop: 'scanWeight '
          },
          {
            label: '交易金额（元）',
            prop: 'transactionAmount '
          }
        ],
        storageList: [{
          storageName: '',
          storageAddress: '',
          storageContact: '',
          storageContactPhone: ''
        }],
        orderId: this.id,
        showGoodsTable: false, // 是否显示货物的表格数据
        showStorageTable: false // 是否显示仓库的表格数据
      };
    },
    created() {
      this.initData();
    },
    computed: {
      // 货物信息数据列
      goodsColumns() {
        let columns = [].concat(this.baseColumns);
        return columns.concat(this.goodsAdditionalCols);
      },
      // 交易信息数据列
      tradeColumns() {
        let columns = [].concat(this.baseColumns);
        return columns.concat(this.tradeAdditionalColumns);
      }
    },
    methods: {
      // 根据找库订单ID获取找库订单的详细数据
      initData() {
        this.ajax({
          type: 'GET',
          url: '/maliwms/instoreOrder/getOrder/' + this.orderId,
          loading: true,
          success: (res) => {
            setTimeout(() => {
              this.$pcNProgress.done();
            }, 300);
            this.data = res.result;
            let cities = res.result.city;
            this.data.city = '';
            let len = cities.length;
            for (let i = 0; i < len; i++) {
              this.data.city += cities[i];
              if (i < (len - 1)) {
                this.data.city += '、';
              }
            }
            // 判断是否有货物的数据
            this.showGoodsTable = res.result.goodsDetails && res.result.goodsDetails.length > 0;
            // 判断是否有仓库的数据
            if (mValidate.stringIsNullOrEmpty(res.result.storageName)) {
              this.showStorageTable = false;
            } else {
              this.showStorageTable = true;
              this.storageList[0].storageContact = res.result.storageContact;
              this.storageList[0].storageContactPhone = res.result.storageContactPhone;
              this.storageList[0].storageId = res.result.storageId;
              this.storageList[0].storageName = res.result.storageName;
              this.storageList[0].storageAddress = res.result.storageAddress;
            }
          }
        });
      },
      // 备注
      getInputVal(val) {
        console.log('input-&#45;&#45;&#45;&#45;', val);
        this.addForm.remark = val;
      },
      // 定义表头的样式
      getHeaderCellClass({ row, column, rowIndex, columnIndex }) {
        if (rowIndex === 0) {
          return 'background: #ffffff; height: 50px';
        } else {
          return '';
        }
      }
    }
  };
</script>
<style>
  .page-audit-sell {
    width: 958px;
  }

  .page-audit-sell .base-info {
    height: auto;
    border-top: 1px solid #e5e5e5;
    border-left: 1px solid #e5e5e5;
    background-color: #f5f6f7
  }
  .page-audit-sell .el-form-item {
    display: inline-block;
    margin-left: 20px;
    margin-right: 20px;
  }
  .page-audit-sell .el-form&#45;&#45;inline .el-form-item__content {
    vertical-align: middle !important;
  }
  .page-audit-sell .goods-title {
    padding-left: 20px;
    height: 50px;
    line-height: 50px;
    width: 100%;
    margin-top: 20px;
    border-left: 1px solid #e5e5e5;
    border-right: 1px solid #e5e5e5;
    border-top: 1px solid #e5e5e5;
    background: white
  }
  .page-audit-sell .trade-date {
    padding-left: 20px;
    height: 50px;
    line-height: 50px;
    width: 100%;
    border-left: 1px solid #e5e5e5;
    border-right: 1px solid #e5e5e5;
    border-top: 1px solid #e5e5e5;
    background: white
  }

  .page-audit-sell .text-div {
    width: 958px;
    height: auto;
    margin-top: 20px;
    padding-bottom: 24px;
    border: 1px solid #e5e5e5;
    background-color: white;
  }

  .page-audit-sell .text-div .text-class {
    margin-top: 20px;
    margin-left: 20px;
    color: #333333;
  }

  .page-audit-sell .maliiconfont {
    color: #ff6c2b;
  }
  .page-audit-sell .btnFrameClass {
    margin-left: 350px;
    margin-top: 40px;
    margin-bottom: 20px;
  }

  .page-audit-sell .singleBtnClass {
    width: 140px;
    height: 40px;
  }
</style>
-->
